import { math } from "../math";

/**
 * 计算函数
 * 实际表格函数的计算
 */
// const calculate = {

/** 四舍五入 */
export const ROUND = (x, y) => {
  const mom = Math.pow(10, y);
  return handleResult(((Number(x) * mom).toFixed() / mom).toFixed(y));
};

/** 求和 */
export const SUM = (x, y) => {
  return handleResult(math.add(x, y));
};

/** 向上取整 */
export const ROUNDUP = (x, y) => {
  const mom = Math.pow(10, y);
  return handleResult(Math.ceil(Number(x) * mom) / mom);
};

/** 向下取整 */
export const ROUNDDOWN = (x, y) => {
  const mom = Math.pow(10, y);
  return handleResult(Math.floor(Number(x) * mom) / mom);
};
// };

function handleResult(s) {
  return Number(s);
}

// export default calculate;
